<script>
export default {
  name: "Server",
  data() {
    return {
      cpu: {},
      memory: {},
      jvm: {},
      system: {},
      disks: {}
    }
  },
  created() {
    this.load();
  },
  methods: {
    load() {
      this.request.get("/monitor/server").then(res => {
        if (res.code === 200) {
          this.cpu = res.data.cpu;
          this.memory = res.data.mem;
          this.jvm = res.data.jvm;
          this.system = res.data.sys;
          this.disks = res.data.sysFiles;
        }
      })
    }
  }
}
</script>

<template>
  <div>
    <el-collapse-transition>
      <div>
    <el-row :gutter="20" style="margin:0 5px">
      <el-col :span="12">
        <el-card>
          <div slot="header">
            <span><i class="el-icon-cpu" style="padding-right: 5px"></i>CPU</span>
          </div>
          <div>
            <table>
              <thead>
              <th>属性</th>
              <th>值</th>
              </thead>
              <tbody>
              <tr>
                <td>核心数</td>
                <td v-if="cpu">{{ cpu.cpuNum }}</td>
              </tr>
              <tr>
                <td>用户使用率</td>
                <td v-if="cpu">{{ cpu.used }}%</td>
              </tr>
              <tr>
                <td>系统使用率</td>
                <td v-if="cpu">{{ cpu.sys }}%</td>
              </tr>
              <tr>
                <td>当前空闲率</td>
                <td v-if="cpu">{{ cpu.free }}%</td>
              </tr>
              </tbody>
            </table>
          </div>
        </el-card>
      </el-col>
      <el-col :span="12">
        <el-card>
          <div slot="header">
            <span><i class="el-icon-tickets" style="padding-right: 5px"></i>内存</span>
          </div>
          <div>
            <table>
              <thead>
              <th>属性</th>
              <th>内存</th>
              <th>JVM</th>
              </thead>
              <tbody>
              <tr>
                <td>总内存</td>
                <td v-if="memory">{{ memory.total }}G</td>
                <td v-if="jvm">{{ jvm.total }}M</td>
              </tr>
              <tr>
                <td>已用内存</td>
                <td v-if="memory">{{ memory.used }}G</td>
                <td v-if="jvm">{{ jvm.used }}M</td>
              </tr>
              <tr>
                <td>剩余内存</td>
                <td v-if="memory">{{ memory.free }}G</td>
                <td v-if="jvm">{{ jvm.free }}M</td>
              </tr>
              <tr>
                <td>使用率</td>
                <td v-if="memory">{{ memory.usage }}%</td>
                <td v-if="jvm">{{ jvm.usage }}%</td>
              </tr>
              </tbody>
            </table>
          </div>
        </el-card>
      </el-col>
    </el-row>
    <el-row style="margin:10px">
      <el-col>
        <el-card>
          <div slot="header">
            <span><i class="el-icon-monitor" style="padding-right: 5px"></i>服务器信息</span>
          </div>
          <div>
            <table>
              <tbody>
              <tr style="border-top: none;">
                <td>服务器名称</td>
                <td v-if="system">{{ system.computerName }}</td>
                <td>操作系统</td>
                <td v-if="system">{{ system.osName }}</td>
              </tr>
              <tr>
                <td>服务器IP</td>
                <td v-if="system">{{ system.computerIp }}</td>
                <td>系统架构</td>
                <td v-if="system">{{ system.osArch }}</td>
              </tr>
              </tbody>
            </table>
          </div>
        </el-card>
      </el-col>
    </el-row>
    <el-row style="margin:10px">
      <el-col>
        <el-card>
          <div slot="header">
            <span><i class="el-icon-coffee-cup" style="padding-right: 5px"></i>Java虚拟机信息</span>
          </div>
          <div>
            <table>
              <tbody>
              <tr style="border-top: none;">
                <td>Java名称</td>
                <td v-if="jvm">{{ jvm.name }}</td>
                <td>Java版本</td>
                <td v-if="jvm">{{ jvm.version }}</td>
              </tr>
              <tr>
                <td>启动时间</td>
                <td v-if="jvm">{{ jvm.startTime }}</td>
                <td>运行时长</td>
                <td v-if="jvm">{{ jvm.runTime }}</td>
              </tr>
              <tr>
                <td>安装路径</td>
                <td v-if="jvm" colspan="3">{{ jvm.home }}</td>
              </tr>
              <tr>
                <td>项目路径</td>
                <td v-if="system" colspan="3">{{ system.userDir }}</td>
              </tr>
              <tr>
                <td>运行参数</td>
                <td v-if="jvm" colspan="3">{{ jvm.inputArgs }}</td>
              </tr>
              </tbody>
            </table>
          </div>
        </el-card>
      </el-col>
    </el-row>
    <el-row style="margin:10px">
      <el-col>
        <el-card>
          <div slot="header">
            <span><i class="el-icon-receiving" style="padding-right: 5px"></i>磁盘状态</span>
          </div>
          <div>
            <table>
              <thead>
              <th>盘符路径</th>
              <th>文件系统</th>
              <th>盘符类型</th>
              <th>总大小</th>
              <th>可用大小</th>
              <th>已用大小</th>
              <th>已用百分比</th>
              </thead>
              <tbody>
              <tr v-for="disk in disks">
                <td v-if="disks">{{disk.dirName}}</td>
                <td v-if="disks">{{disk.sysTypeName}}</td>
                <td v-if="disks">{{disk.typeName}}</td>
                <td v-if="disks">{{disk.total}}</td>
                <td v-if="disks">{{disk.free}}</td>
                <td v-if="disks">{{disk.used}}</td>
                <td v-if="disks">{{disk.usage}}%</td>
              </tr>
              </tbody>
            </table>
          </div>
        </el-card>
      </el-col>
    </el-row>
      </div>
      </el-collapse-transition>
  </div>
</template>

<style scoped>
.el-card /deep/ .el-card__header {
  padding: 10px 20px;
  border-bottom: 1px solid #EBEEF5;
  box-sizing: border-box;
}

table {
  text-align: left;
  font-size: 17px;
  width:99%;
  margin:0 auto;
  table-layout: fixed;
  line-height: 40px;
  border-spacing: 300px;
  border-collapse: collapse;
}

table th {
  color: #a4a7ac;
}

table tr {
  border: 1px solid #dfe6ec;
  border-left: none;
  border-right: none;
}


</style>
